from aip import AipOcr, AipBodyAnalysis
import re

class Bd:
    """
    加载配置
    """
    def __init__(self):
        """ 你的 APPID AK SK """
        self.W_APP_ID = '18608539'
        self.API_KEY = 'a5aca6768d344067a9e563a7f000aa0d'
        self.SECRET_KEY = 'b1fa353db4de44e1992fb0c72166dc9c'


    """ 读取图片 """

    def wz(self,img_file):
        """ 连接接口,鉴权 """
        client = AipOcr(self.W_APP_ID, self.API_KEY, self.SECRET_KEY)
        """ 调用通用文字识别, 图片参数为本地图片 """
        data = client.basicGeneral(img_file)
        print(data)
        data = str(data)

        ds = re.compile(r"{'words': '(.*?)'}")      # 正则匹配
        res = ds.findall(data)                      # 获取所有匹配到的数据
        # print(res)
        # res = data['words_result'][0]['words']
        for i in res:
            print(i)


if __name__ == '__main__':

    bd = Bd()
    with open('1.jpg','rb') as f:
        bd.wz(f.read())






